version 8.2
capture clear
capture log close
set more off
set mem 1000m
set mat 800



use "GDP per capita2.dta" 


/*Download:
GDP per capita PPP constant 2011 
GDP PPP constant 2011 
*and all other GDP in US$
Gross savings (% of GDP)
Population growth
School enrollment secondary (% gross)
population total
population 15-64

download 1990-2017
*/

sort countryname time

*dependent variable:
ren gdppercapitapppconstant2011inter gdppercapita
label variable gdppercapita "GDP per capita, PPP"
gen log_gdppercapita=log(gdppercapita)
label variable log_gdppercapita "Log GDP per capita, PPP"
sum log_gdppercapita
gen log_gdppercapita_st=(log_gdppercapita-8.928119)/1.248689
sum log_gdppercapita_st
label variable log_gdppercapita_st "Log GDP per capita standardized, PPP"

   

   
***create an imputed value for GDP:
replace  gdppppconstant2011internationaln=gdppppcurrentinternationalnygdpm if gdppppconstant2011internationaln==.
replace  gdppppconstant2011internationaln=gdpcurrentusnygdpmktpcd if gdppppconstant2011internationaln==.
replace  gdppppconstant2011internationaln=gdpconstant2010usnygdpmktpkd if gdppppconstant2011internationaln==.



gen log_gdppercapita2=log(gdppppconstant2011internationaln/populationtotalsppoptotl)

*replace  gdppppconstant2011internationaln=gdppppconstant2011internationaln[_n-1] if countryname==countryname[_n-1]

browse countryname time gdppppconstant2011internationaln


***create interpolated data for Cambodia 2016
*expand 2 in 840
*replace time=2016 if countryname=="Cambodia"&time==2015&time[_n-1]==2015
*sort countryname time 
 
**Control variables from Mankiw:  a contribution to the empirics of economic growth
**all proportions stansdardized between 0 and 1

gen log_s=log(grosssavingsofgdpnygnsictrzs/100)
label variable log_s "log(s)"

gen log_ngd=log(populationgrowthannualsppopgrow/100+0.05)
label variable log_ngd "log(n+g+d)"

gen log_s_ngd=log_s-log_ngd
label variable log_s_ngd "log(s)-log(n+g+d)"

gen school=schoolenrollmentsecondarygrossse/populationtotalsppoptotl*populationages1564totalsppop1564
gen log_school=log(school/100)
label variable log_school "log(school)"


ren time year
sort countryname year
*browse countryname year gdppppconstant2011internationaln if countryname=="Lao PDR"

save "GDP per capita_clean2.dta", replace


use "Foreign aid.dta"
ren time year
ren netodareceivedpercapitacurrentus foreign_aid
keep countryname year foreign_aid 
sort countryname year
save "Foreign aid_clean.dta", replace

use "PPP exchange rate2.dta"
ren time year
sort countryname year
save "PPP exchange rate2_clean.dta", replace


use "GDP per employed.dta"
*ren time year
sort countryname time
browse
save "GDP per employed_clean.dta", replace



exit
